var util = require('../../libs/util.js');
var app = getApp();
Page({
  data: {
    id: '',
    name: '',
    wholemile: '',
    mile: '',
    subsidy: 0
  },
  onShareAppMessage: function () {
    return {
      title: app.appName,
      path: '/pages/index/index'
    }
  },
  onLoad: function (e) {
    wx.setNavigationBarTitle({ "title": app.appName +"--收货点信息" });
    this.setData({
      id: e.id,
      name: e.name,
      wholemile: e.wholemile,
      mile: e.mile,
      subsidy: e.subsidy
    });
  },
  onReady: function () {
    wx.hideToast()
  },
  bindInput: function (e) {
    var item = String(e.currentTarget.id), item_value = {};
    item_value[item] = e.detail.value;
    this.setData(item_value);
  },
  confirmData: function () {
    wx.showLoading({
      title: '请稍候...',
    });
    util.putData("settingPath", {
      id: this.data.id,
      wholemile: this.data.wholemile,
      mile: this.data.mile,
      subsidy: this.data.subsidy
    }, function (res, error) {
      //console.log(res); console.log(error)
      wx.hideLoading();
      if (error) {
        wx.showToast({
          title: res.data.data,
          image: '/images/wrong.png',
          duration: 3000
        });
        return false;
      }
      if (res.data.success) {
        wx.showLoading({
          title: "设置成功",
          icon: 'success',
          success: function () {
            setTimeout(function () {
              wx.redirectTo({
                url: '/pages/schedule/path'
              })
            }, 3000);
          }
        });
      }
    });
  },
  cancelConfirmData: function () {
    wx.redirectTo({
      url: '/pages/schedule/path'
    })
  }
});